< previous page page_435 next page >

Page 435
You dont apply the UBound and LBound functions to collections like you do with arrays.
Collections are zero based, so their Index starts at zero (0).
Collections have a Count property that tells you how many elements the collection contains.
The Forms Collection
The Forms collection is global, so you can refer to it anywhere in your program. The Forms collection only contains those forms that are currently loaded at runtime. You might have 10 forms in your project file, but if only four of them are loaded and/or displayed on the screen, then only those four are contained in the Forms collection. The order of the forms in the collection is arbitrary and changes as forms are loaded and unloaded.
Forms is a Visual Basic reserved word. This means you cannot declare a variable with this name. To loop through all the loaded forms in an application, you can use the following code:
9f31265bb40b592b1929e18a47ab28e5.gif
Dim intLoop As Integer

For intLoop = 0 to Forms.Count - 1
   Forms(intLoop).BackColor = 255
Next
For Each. . .Next
The For Each...Next construct also allows you to iterate through a collection of objects. You should get used to using this construct because its much more efficient than the previously shown loop:
9f31265bb40b592b1929e18a47ab28e5.gif
Dim frmAny As Form

For Each...frmAny In Forms
   frmAny.BackColor = 255
Next
The For...Each loop works through an enumeration method thats attached to every collection. This enumeration method keeps track of which object in the collection was just accessed, and it returns the next object the next time through the

 
< previous page page_435 next page >

If you like this book, buy it!